﻿Imports System.Drawing
Imports System.Windows.Forms
Imports System.Data.SqlClient
Public Class ctrQuanTheoDoi
    Dim conn = New SqlConnection

    Private dtTimKiem As New DataTable
    'Khai báo chuỗi kết nối Database
    Private strConnection As String = ""
    'Khai bao bien kiem tra loi
    Private strError As String = ""
    Private blnCapNhat As Boolean = False
    'Khai báo Mã hồ sơ cấp GCN, phục vụ cho việc liệt kê 10 thửa đất mới thao tác trong thời gian gần nhất
    Public strMaHoSoCapGCN As String = ""
    Private strMaThuaDat As String = ""
    Private strMaDonViHanhChinh As String = ""
    Public strToBanDo As String = ""
    Public strSoThua As String = ""
    Public strDiaChiThua As String = ""
    'Khai báo thuộc tính chuỗi kết nối Database
    Private strusername As String = ""

    Dim dthosoguilenquan As New DataTable
    Dim dthosobitralai As New DataTable
    Public Property MaThuaDat() As String
        Get
            Return strMaThuaDat
        End Get
        Set(ByVal value As String)
            strMaThuaDat = value
        End Set
    End Property
    Public Property UserName() As String
        Get
            Return strusername
        End Get
        Set(ByVal value As String)
            strusername = value
        End Set
    End Property

    Public Property Connection() As String
        Get
            Return strConnection
        End Get
        Set(ByVal value As String)
            strConnection = value
        End Set
    End Property
    Public Property ToBanDo() As String
        Get
            Return strToBanDo
        End Get
        Set(ByVal value As String)
            strToBanDo = value
        End Set
    End Property

    Public Property SoThua() As String
        Get
            Return strSoThua
        End Get
        Set(ByVal value As String)
            strSoThua = value
        End Set
    End Property

    Public Property DiaChiThua() As String
        Get
            Return strDiaChiThua
        End Get
        Set(ByVal value As String)
            strDiaChiThua = value
        End Set
    End Property


    Public Property MaDonViHanhChinh() As String
        Get
            Return strMaDonViHanhChinh
        End Get
        Set(ByVal value As String)
            strMaDonViHanhChinh = value
        End Set
    End Property
    Public ReadOnly Property MaHoSoCapGCN() As String
        Get
            Return strMaHoSoCapGCN
        End Get
    End Property
    Public strDienTich As String = ""
    Public Property DienTich() As String
        Get
            Return strDienTich
        End Get
        Set(ByVal value As String)
            strDienTich = value
        End Set
    End Property
    Public Sub ctrTheoDoi_Load() '(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cls As New classtheodoi
        cls.Connection = strConnection
        'Button14.Cursor = Cursors.WaitCursor
        If (strMaDonViHanhChinh = 0) Then
            MessageBox.Show("Chọn đơn vị hành chính", "DMCLand", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If

        Dim parasHoSoGui() As String = {"@MaDonViHanhChinh", "@Flag", "@ToBanDo", "@SoThua", "@DiaChi"}
        Dim ValuesHoSoGui() As String = {strMaDonViHanhChinh, "1", "", "", ""}

        Dim parasHoSoTraLai() As String = {"@MaDonViHanhChinh", "@Flag", "@ToBanDo", "@SoThua", "@DiaChi"}
        Dim ValuesHoSoTraLai() As String = {strMaDonViHanhChinh, "0", "", "", ""}
        dthosoguilenquan.Clear()
        dthosobitralai.Clear()

        dthosoguilenquan = cls.GetData_SP("SPLoadHoSoPhuongQuan", parasHoSoGui, ValuesHoSoGui)        
        dthosobitralai = cls.GetData_SP("SPLoadHoSoPhuongQuan", parasHoSoTraLai, ValuesHoSoTraLai)

        CtrlGridView1.DataSource = dthosoguilenquan
        'MessageBox.Show(dthosoguilenquan.Rows.Count.ToString(), "Số hồ sơ chờ quận xử lý")


        CtrlGridView1.Columns("MaHoSoCapGCN").Visible = False
        CtrlGridView1.Columns("ToBanDo").HeaderText = "Tờ bản đồ"
        CtrlGridView1.Columns("SoThua").HeaderText = "Số thửa"
        CtrlGridView1.Columns("TenPhuong").HeaderText = "Tên phường Gửi"
        CtrlGridView1.Columns("DiaChi").HeaderText = "Địa chỉ thửa"
        CtrlGridView1.Columns("DiaChi").Width = 300
        CtrlGridView1.Columns("NguoiGui").HeaderText = "Tên người gửi"
        CtrlGridView1.Columns("NguoiGui").Width = 100
        CtrlGridView1.Columns("NgayGui").HeaderText = "Ngày Gửi"
        CtrlGridView1.Columns("NgayGui").DefaultCellStyle.Format = "dd / MM / yyyy"
        CtrlGridView1.Columns("MaDonViHanhChinh").Visible = False
        CtrlGridView1.Columns("MaThuaDat").Visible = False
        CtrlGridView1.Columns("DienTichTuNhien").Visible = False
        CtrlGridView1.Columns("LyDoGuiVe").HeaderText = "Gửi lên quận"
        CtrlGridView1.Columns("LyDoGuiVe").Width = 120


        CtrlGridView2.DataSource = dthosobitralai

        CtrlGridView2.Columns("MaHoSoCapGCN").Visible = False
        CtrlGridView2.Columns("ToBanDo").HeaderText = "Tờ bản đồ"
        CtrlGridView2.Columns("SoThua").HeaderText = "Số thửa"
        CtrlGridView2.Columns("TenPhuong").HeaderText = "Tên phường Gửi"
        CtrlGridView2.Columns("DiaChi").HeaderText = "Địa chỉ thửa"
        CtrlGridView2.Columns("DiaChi").Width = 300
        CtrlGridView2.Columns("NguoiGui").HeaderText = "Tên người trả"
        CtrlGridView2.Columns("NguoiGui").Width = 100
        CtrlGridView2.Columns("NgayGui").HeaderText = "Ngày trả"
        CtrlGridView2.Columns("NgayGui").DefaultCellStyle.Format = "dd / MM / yyyy"
        CtrlGridView2.Columns("MaDonViHanhChinh").Visible = False
        CtrlGridView2.Columns("LyDoGuiVe").HeaderText = "Lý do gửi trả lại"
        CtrlGridView2.Columns("LyDoGuiVe").Width = 120
        CtrlGridView2.Columns("MaThuaDat").Visible = False
        CtrlGridView2.Columns("TrangThaiHoSo").Visible = False
        CtrlGridView2.Columns("DienTichTuNhien").Visible = False

        If (CtrlGridView3.Columns.Count = 0) Then
            Me.AddColumnsTacNghiep()
        End If
    End Sub
    Public Sub AddColumnsTacNghiep()
        Dim txtClnToBanDoTacNghiep As New DataGridViewTextBoxColumn
        Dim txtClnSoThuaTacNghiep As New DataGridViewTextBoxColumn
        Dim txtClnDienTichTacNghiep As New DataGridViewTextBoxColumn
        Dim txtClnDiaChiThuaTacNghiep As New DataGridViewTextBoxColumn
        Dim txtClnNgayLapToTrinhTacNghiep As New DataGridViewTextBoxColumn
        Dim txtClnNgayQuyetDinhCapGCNTacNghiep As New DataGridViewTextBoxColumn
        Dim txtClnHoTenTacNghiep As New DataGridViewTextBoxColumn
        Dim txtClnHoTenChuChuyenNhuongTacNghiep As New DataGridViewTextBoxColumn
        Dim txtClnMaLoaiBienDong As New DataGridViewTextBoxColumn
        Dim txtClnCanhBaoTranhChap As New DataGridViewTextBoxColumn

        'Dim txtClnSoDinhDanhTacNghiep As New DataGridViewTextBoxColumn
        Try
            'Tờ bản đồ
            With txtClnToBanDoTacNghiep
                .HeaderText = "Tờ bản đồ"
                .Name = "ToBanDo"
                .Width = 100
            End With
            'Số hiệu thửa
            With txtClnSoThuaTacNghiep
                .HeaderText = "Số thửa"
                .Name = "SoThua"
                .Width = 100
            End With

            With txtClnDiaChiThuaTacNghiep
                .HeaderText = "Địa chỉ đất"
                .Name = "DiaChi"
                .Width = 400
            End With

            'With txtClnSoDinhDanhTacNghiep
            '    .HeaderText = "Số định danh"
            '    .Name = "SoDinhDanhTacNghiep"
            '    .Width = 100
            'End With
            'Add all to DataGridView
            With Me.CtrlGridView3
                .BorderStyle = Windows.Forms.BorderStyle.Fixed3D
                .RowHeadersVisible = False
                .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                'Add Columns
                With .Columns
                    .Add(txtClnToBanDoTacNghiep)
                    .Add(txtClnSoThuaTacNghiep)
                    .Add(txtClnDiaChiThuaTacNghiep)

                End With
                'Không cho phép thêm
                .AllowUserToAddRows = False
                'Không cho phép xóa
                .AllowUserToDeleteRows = False
                .ScrollBars = ScrollBars.Both
                'Không lựa chọn bất kỳ dòng nào
                .ClearSelection()
            End With
        Catch ex As Exception
            strError = ex.Message
            MsgBox(" Tìm kiếm" + vbNewLine + " Lỗi: " & vbNewLine & strError, MsgBoxStyle.Information, "DMCLand")
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ctrtimkiem()
    End Sub
    Public Sub ctrtimkiem() '(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cls As New classtheodoi
        cls.Connection = strConnection
        'Button14.Cursor = Cursors.WaitCursor
        If (strMaDonViHanhChinh = 0) Then
            MessageBox.Show("Chọn đơn vị hành chính", "DMCLand", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If


        Dim parasHoSoGui() As String = {"@MaDonViHanhChinh", "@Flag", "@ToBanDo", "@SoThua", "@DiaChi"}
        Dim ValuesHoSoGui() As String = {strMaDonViHanhChinh, "2", txttobando.Text.Trim.ToString(), txtsothua.Text.Trim.ToString, txtdiachi.Text.Trim.ToString}

        dthosoguilenquan.Clear()
        'dthosobitralai.Clear()

        dthosoguilenquan = cls.GetData_SP("SPLoadHoSoPhuongQuan", parasHoSoGui, ValuesHoSoGui)
        'dthosobitralai = cls.GetData_SP("SPLoadHoSoPhuongQuan", parasHoSoTraLai, ValuesHoSoTraLai)

        CtrlGridView1.DataSource = dthosoguilenquan


        CtrlGridView1.Columns("MaHoSoCapGCN").Visible = False
        CtrlGridView1.Columns("ToBanDo").HeaderText = "Tờ bản đồ"
        CtrlGridView1.Columns("SoThua").HeaderText = "Số thửa"
        CtrlGridView1.Columns("TenPhuong").HeaderText = "Tên phường Gửi"
        CtrlGridView1.Columns("DiaChi").HeaderText = "Địa chỉ thửa"
        CtrlGridView1.Columns("DiaChi").Width = 300
        CtrlGridView1.Columns("NguoiGui").HeaderText = "Tên người gửi"
        CtrlGridView1.Columns("NguoiGui").Width = 100
        CtrlGridView1.Columns("NgayGui").HeaderText = "Ngày Gửi"
        CtrlGridView1.Columns("NgayGui").DefaultCellStyle.Format = "dd / MM / yyyy"
        CtrlGridView1.Columns("MaDonViHanhChinh").Visible = False
        CtrlGridView1.Columns("MaThuaDat").Visible = False
        CtrlGridView1.Columns("DienTichTuNhien").Visible = False
        CtrlGridView1.Columns("TrangThaiHoSo").HeaderText = "Trạng thái hồ sơ"
        'CtrlGridView1.Columns("LyDoGuiVe").HeaderText = "Lý do gửi trả lại"
        'CtrlGridView1.Columns("LyDoGuiVe").Width = 120

        dthosobitralai.Clear()
        CtrlGridView2.DataSource = dthosobitralai
        'CtrlGridView2.DataSource = dthosobitralai

        'CtrlGridView2.Columns("MaHoSoCapGCN").Visible = False
        'CtrlGridView2.Columns("ToBanDo").HeaderText = "Tờ bản đồ"
        'CtrlGridView2.Columns("SoThua").HeaderText = "Số thửa"
        'CtrlGridView2.Columns("TenPhuong").HeaderText = "Tên phường Gửi"
        'CtrlGridView2.Columns("DiaChi").HeaderText = "Địa chỉ thửa"
        'CtrlGridView2.Columns("DiaChi").Width = 300
        'CtrlGridView2.Columns("NguoiGui").HeaderText = "Tên người trả"
        'CtrlGridView2.Columns("NguoiGui").Width = 100
        'CtrlGridView2.Columns("NgayGui").HeaderText = "Ngày trả"
        'CtrlGridView2.Columns("NgayGui").DefaultCellStyle.Format = "dd / MM / yyyy"
        'CtrlGridView2.Columns("MaDonViHanhChinh").Visible = False
        'CtrlGridView2.Columns("LyDoGuiVe").HeaderText = "Lý do gửi trả lại"
        'CtrlGridView2.Columns("LyDoGuiVe").Width = 120
        'CtrlGridView1.Columns("MaThuaDat").Visible = False
        'CtrlGridView1.Columns("TrangThaiHoSo").Visible = False
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ctrTheoDoi_Load()
    End Sub

    'Private Sub CtrlGridView2_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles CtrlGridView2.CellMouseClick
    '    If (e.Button.ToString = "Right") And (e.RowIndex >= 0) Then

    '        Try
    '            With CtrlGridView2
    '                .ClearSelection()
    '                .Rows(e.RowIndex).Selected = True
    '            End With
    '            With dthosobitralai.Rows(e.RowIndex)
    '                'Gan gia tri vao bien dung chung
    '                strMaThuaDat = ""
    '                Try
    '                    strMaThuaDat = .Item("MaThuaDat").ToString
    '                Catch ex As Exception
    '                    strMaThuaDat = ""
    '                End Try

    '                strMaHoSoCapGCN = ""

    '                strMaHoSoCapGCN = .Item("MaHoSoCapGCN").ToString
    '                ' strmakhoahoso = MaLoaiBienDong(strMaHoSoCapGCN)
    '                'Hien thi ban ghi lua chon len Danh sach thua can tac nghiep
    '                CtrlGridView3.RowCount = 1
    '                CtrlGridView3.Item("ToBanDo", 0).Value = .Item("ToBanDo").ToString
    '                strToBanDo = .Item("ToBanDo").ToString
    '                CtrlGridView3.Item("SoThua", 0).Value = .Item("SoThua").ToString
    '                strSoThua = .Item("SoThua").ToString
    '                CtrlGridView3.Item("DiaChi", 0).Value = .Item("DiaChi").ToString
    '                strDiaChiThua = .Item("DiaChi").ToString
    '                strDienTich = .Item("DienTichTuNhien").ToString
    '            End With
    '            'Trang thai chuc nang 
    '            blnCapNhat = False
    '        Catch ex As Exception
    '            strError = ex.Message
    '            MsgBox("Tìm kiếm: " & vbNewLine & "Lỗi: " & vbNewLine + ex.Message, MsgBoxStyle.Information, "DMCLand")
    '        End Try
    '    End If
    'End Sub

    Private Sub CtrlGridView1_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles CtrlGridView1.CellMouseClick
        If (e.Button.ToString = "Right") And (e.RowIndex >= 0) Then

            Try
                With CtrlGridView1
                    .ClearSelection()
                    .Rows(e.RowIndex).Selected = True
                End With
                With dthosoguilenquan.Rows(e.RowIndex)
                    'Gan gia tri vao bien dung chung
                    strMaThuaDat = ""
                    Try
                        strMaThuaDat = .Item("MaThuaDat").ToString
                    Catch ex As Exception
                        strMaThuaDat = ""
                    End Try

                    strMaHoSoCapGCN = ""

                    strMaHoSoCapGCN = .Item("MaHoSoCapGCN").ToString
                    ' strmakhoahoso = MaLoaiBienDong(strMaHoSoCapGCN)
                    'Hien thi ban ghi lua chon len Danh sach thua can tac nghiep
                    CtrlGridView3.RowCount = 1
                    CtrlGridView3.Item("ToBanDo", 0).Value = .Item("ToBanDo").ToString
                    strToBanDo = .Item("ToBanDo").ToString
                    CtrlGridView3.Item("SoThua", 0).Value = .Item("SoThua").ToString
                    strSoThua = .Item("SoThua").ToString
                    CtrlGridView3.Item("DiaChi", 0).Value = .Item("DiaChi").ToString
                    strDiaChiThua = .Item("DiaChi").ToString
                    strDienTich = .Item("DienTichTuNhien").ToString

                End With
                'Trang thai chuc nang 
                blnCapNhat = False
            Catch ex As Exception
                strError = ex.Message
                MsgBox("Tìm kiếm: " & vbNewLine & "Lỗi: " & vbNewLine + ex.Message, MsgBoxStyle.Information, "DMCLand")
            End Try
        End If
    End Sub

    Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ctrTheoDoi_Load()
    End Sub
End Class
